LiveUser_Admin
[ class tree: LiveUser_Admin ] [ index: LiveUser_Admin ] [ all elements ]

Source for file UserRights.php

Documentation is available at UserRights.php

  1. <?php require_once 'index.php'?>
  2. <h3>UserRights</h3>
  3. <?php
  4. $currentUser $admin->searchUsers();
  5. if  (empty($currentUser)) {
  6.     echo 'Run the <b>User</b> test first<br />';
  7.     exit;
  8. }
  9.  
  10. $currentRight $admin->perm->getRights();
  11. if  (empty($currentRight)) {
  12.     echo 'Run the <b>Right</b> test first<br />';
  13.     exit;
  14. }
  15.  
  16. $users $admin->searchUsers();
  17. $rights $admin->perm->getRights();
  18.  
  19. for ($i = 1; $i < 30; $i++{
  20.     $randUser array_rand($users);
  21.     $randRight array_rand($rights);
  22.     $data = array(
  23.         'perm_user_id' => $users[$randUser]['perm_user_id'],
  24.         'right_id' => $rights[$randRight]['right_id'],
  25.         'right_level' => 1,
  26.     );
  27.     $granted $admin->perm->grantUserRight($data);
  28.  
  29.     if ($granted === false{
  30.         echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  31.     else {
  32.         echo '<b>' $users[$randUser]['name''</b> was granted the right <b>' $rights[$randRight]['right_id''</b><br />';
  33.     }
  34.     unset($rights[$randRight]);
  35.     $rights array_values($rights);
  36. }
  37.  
  38. $randUser array_rand($users);
  39. $randRight array_rand($rights);
  40. $filters = array(
  41.     'perm_user_id' => $users[$randUser]['auth_user_id'],
  42.     'right_id' => $rights[$randRight]['right_id']
  43. );
  44. $revoked $admin->perm->revokeUserRight($filters);
  45.  
  46. if ($revoked === false{
  47.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  48. else {
  49.     echo 'The right <b>' $rights[$randRight]['right_id''</b> has been revoked from <b>' $users[$randUser]['name''</b><br />';
  50. }
  51.  
  52. $randUser array_rand($users);
  53. $params = array(
  54.     'fields' => array(
  55.         'right_id'
  56.     ),
  57.     'filters' => array(
  58.         'perm_user_id' => $users[$randUser]['perm_user_id']
  59.     )
  60. );
  61. $user_rights $admin->perm->getRights($params);
  62. if ($user_rights === false{
  63.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  64. else {
  65.     $randRight array_rand($user_rights);
  66.     $filters = array(
  67.         'perm_user_id' => $users[$randUser]['auth_user_id'],
  68.         'right_id' => $user_rights[$randRight]['right_id']
  69.     );
  70.     $data = array('right_level' => 3);
  71.     $update $admin->perm->updateUserRight($data$filters);
  72.     if ($update === false{
  73.         echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  74.     else {
  75.         echo 'The right <b>' $user_rights[$randRight]['right_id''</b> has been updated to Level 3 for <b>' $users[$randUser]['name''</b><br />';
  76.         $params = array(
  77.             'filters' => array(
  78.                 'right_id' => $user_rights[$randRight]['right_id'],
  79.                 'perm_user_id' => $users[$randUser]['perm_user_id']
  80.             )
  81.         );
  82.         $result $admin->perm->getRights($params);
  83.  
  84.         if ($result === false{
  85.             echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  86.         else {
  87.             Var_Dump::display($result);
  88.         }
  89.     }
  90. }    
  91.  
  92. $randUser array_rand($users);
  93. $params = array(
  94.     'fields' => array(
  95.         'right_id',
  96.         'right_level'
  97.     ),
  98.     'with' => array(
  99.         'perm_user_id' => array(
  100.             'fields' => array(
  101.                 'name',
  102.             ),
  103.         ),
  104.     ),
  105.     'filters' => array(
  106.         'perm_user_id' => $users[$randUser]['perm_user_id']
  107.     )
  108. );
  109. $singleRight $admin->perm->getRights($params);
  110.  
  111. if ($singleRight === false{
  112.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  113. else {
  114.     echo 'These are the user rights for <b>' $users[$randUser]['name''</b>:<br />';
  115.     Var_Dump::display($singleRight);
  116.     echo '<br />';
  117. }
  118.  
  119. $params = array(
  120.     'fields' => array(
  121.         'right_id',
  122.         'right_level'
  123.     ),
  124.     'with' => array(
  125.         'perm_user_id' => array(
  126.             'fields' => array(
  127.                 'name',
  128.             ),
  129.         ),
  130.     ),
  131. );
  132. $allRights $admin->perm->getRights($params);
  133. if ($allRights === false{
  134.     echo '<strong>Error on line: '.__LINE__.' last query: '.$admin->perm->_storage->dbc->last_query.'</strong><br />';
  135. else {
  136.     echo 'Here are all the rights:<br />';
  137.     Var_Dump::display($allRights);
  138.     echo '<br />';
  139. }
  140. echo '<hr />';

Documentation generated on Mon, 11 Mar 2019 14:00:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.